package com.bruce.demo2.patterns.demo2.structural.demo12.flyweight.demo2;

import java.util.HashMap;
import java.util.Map;

/**
 * @PROJECT_NAME: design_patterns
 * @DESCRIPTION: Tank工厂类
 * @AUTHOR: CNBruceLee
 * @DATE: 2021/8/3 5:55
 */
public class TankFactory {
    private Map<String, ITank> tankMap;

    private TankFactory() {
        tankMap = new HashMap<String, ITank>();
        tankMap.put("T70", new Tank70());
        tankMap.put("T90", new Tank90());
    }

    private static TankFactory tankFactory = new TankFactory();

    public static TankFactory getInstance() {
        return tankFactory;
    }

    public ITank getTank(String key) {
        if (tankMap.containsKey(key)) {
            return tankMap.get(key);
        }
        throw new RuntimeException("没有此种坦克");
    }

}
